<template>
	<view class="user-stats-page">
		<!-- 统计概览卡片 -->
		<view class="stats-overview">
			<view class="stats-card">
				<view class="stats-icon">
					<uni-icons type="notification" size="36" color="#165DFF"></uni-icons>
				</view>
				<view class="stats-info">
					<view class="stats-value">{{ totalVotes }}</view>
					<view class="stats-label">总投票次数</view>
				</view>
			</view>

			<view class="stats-card">
				<view class="stats-icon">
					<uni-icons type="checkbox" size="36" color="#00B42A"></uni-icons>
				</view>
				<view class="stats-info">
					<view class="stats-value">{{ endedVotes }}</view>
					<view class="stats-label">已结束投票</view>
				</view>
			</view>

			<view class="stats-card">
				<view class="stats-icon">
					<uni-icons type="locked" size="36" color="#FF7D00"></uni-icons>
				</view>
				<view class="stats-info">
					<view class="stats-value">{{ ongoingVotes }}</view>
					<view class="stats-label">进行中投票</view>
				</view>
			</view>
		</view>

		<!-- 投票类别分布图表 -->
		<!--   <view class="chart-container">
      <view class="chart-title">投票类别分布</view>
      <view class="chart-wrapper">
        <qiun-data-charts 
          type="pie" 
          :chartData="categoryData" 
          :opts="chartOpts"
          width="750rpx"
          height="400rpx"
        ></qiun-data-charts>
      </view>
    </view> -->

		<!-- 投票行为详情 -->
		<view class="stats-detail">
			<view class="detail-item">
				<view class="detail-label">最近投票</view>
				<view class="detail-value">{{ lastVoteTime || '暂无记录' }}</view>
			</view>

			<view class="detail-item">
				<view class="detail-label">胜出记录</view>
				<view class="detail-value">{{ winCount }}次（你支持的选项最终胜出）</view>
			</view>

			<view class="detail-item">
				<view class="detail-label">活跃度</view>
				<view class="detail-value">
					<view class="activity-tag" :class="activityLevel">{{ activityText }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue'
	import {
		countVotesByUserId,
		countVotesStatusByUserId
	} from '@/api/vote.js'
	import {
		onShow
	} from '@dcloudio/uni-app';
	import * as echarts from 'echarts'

	// 统计数据
	const totalVotes = ref(0);
	const endedVotes = ref(0)
	const ongoingVotes = ref(0)

	const initData = async () => {
		const res = await countVotesByUserId()
		totalVotes.value = res.data.total;
		const resEndStatus = await countVotesStatusByUserId(2)
		resEndStatus.value = resEndStatus.data.total;
		const resongoingStatus = await countVotesStatusByUserId(1)
		ongoingVotes.value = resongoingStatus.data.total;
	}

	onShow(() => {
		initData()
	})
</script>

<style lang="less" scoped>
	.user-stats-page {
		padding: 20rpx;
		background-color: #F5F7FA;
		min-height: 100vh;
	}

	/* 概览卡片 */
	.stats-overview {
		display: flex;
		gap: 20rpx;
		margin-bottom: 30rpx;
	}

	.stats-card {
		flex: 1;
		background-color: #FFFFFF;
		border-radius: 16rpx;
		padding: 30rpx 20rpx;
		display: flex;
		align-items: center;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.stats-icon {
		width: 80rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: rgba(22, 93, 255, 0.1);
		border-radius: 12rpx;
		margin-right: 20rpx;
	}

	.stats-value {
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
	}

	.stats-label {
		font-size: 24rpx;
		color: #666666;
		margin-top: 5rpx;
	}

	/* 图表容器 */
	.chart-container {
		background-color: #FFFFFF;
		border-radius: 16rpx;
		padding: 30rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.chart-title {
		font-size: 28rpx;
		font-weight: 500;
		color: #333333;
		margin-bottom: 20rpx;
	}

	/* 详情列表 */
	.stats-detail {
		background-color: #FFFFFF;
		border-radius: 16rpx;
		padding: 10rpx 30rpx;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.detail-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.detail-item:last-child {
		border-bottom: none;
	}

	.detail-label {
		font-size: 26rpx;
		color: #666666;
	}

	.detail-value {
		font-size: 26rpx;
		color: #333333;
	}

	/* 活跃度标签 */
	.activity-tag {
		padding: 8rpx 20rpx;
		border-radius: 20rpx;
		font-size: 22rpx;
		font-weight: 500;
	}

	.activity-tag.high {
		background-color: rgba(0, 180, 42, 0.1);
		color: #00B42A;
	}

	.activity-tag.medium {
		background-color: rgba(255, 125, 0, 0.1);
		color: #FF7D00;
	}

	.activity-tag.low {
		background-color: rgba(153, 153, 153, 0.1);
		color: #999999;
	}
</style>